{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from histogram import gen_histogram_ymax_bw\n",
    "import numpy as np\n",
    "from statsmodels.iolib.foreign import genfromdta\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "plt.rcParams['pdf.fonttype'] = 42\n",
    "plt.rcParams['ps.fonttype'] = 42\n",
    "\n",
    "% matplotlib inline      \n",
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# read in the stata data\n",
    "statadata = 'ratings_by_person.dta'\n",
    "\n",
    "df=genfromdta(fname=statadata, missing_flt=-9999.0, encoding=None,\n",
    "                pandas=True, convert_dates=True)\n",
    "# replace missing values with nan\n",
    "df = df.replace(to_replace=-9999.0,value=np.nan)\n",
    "df = df.dropna()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "style = 'grayscale' # 'ggplot' # 'bmh' 'fivethirtyeight' 'ggplot' 'grayscale'\n",
    "ylabel = 'Density'\n",
    "\n",
    "# RATING HISTOGRAM FOR WOMEN\n",
    "plotdata = df[df.female==1]\n",
    "nbins=15\n",
    "\n",
    "x = np.array( plotdata.rating.copy() ); xlabel = r'Attractiveness Rating'\n",
    "filename = 'figures/hist_rating_women'\n",
    "\n",
    "gen_histogram_ymax_bw(x=x,nbins=nbins,xlabel=xlabel,ylabel=ylabel,label_fontsize=14,xaxis_min=1.0,xaxis_max = 5.00,yaxis_max= 0.80,\n",
    "              box_xcoord=0.60, box_ycoord=0.95,style=style,filename=filename)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# RATING HISTOGRAM FOR MEN\n",
    "plotdata = df[df.female==0]\n",
    "nbins=15\n",
    "\n",
    "x = np.array( plotdata.rating.copy() ); xlabel = r'Attractiveness Rating'\n",
    "filename = 'figures/hist_rating_men'\n",
    "\n",
    "gen_histogram_ymax_bw(x=x,nbins=nbins,xlabel=xlabel,ylabel=ylabel,label_fontsize=14,xaxis_min=1.0,xaxis_max = 5.00,yaxis_max= 0.80,\n",
    "              box_xcoord=0.60, box_ycoord=0.95,style=style,filename=filename)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda root]",
   "language": "python",
   "name": "conda-root-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
